package com.atguigu.leetcode;

/**
 * 阶乘
 *
 * @author xr-8
 * @date 2024-06-18
 * @time 18:49
 */
public class Factorial {
    public static void main(String[] args) {
        System.out.println(factorialSum(30,0));
    }

    /**
     * 阶乘和
     * @return
     */
    public static int factorialSum(int start, int sum) {
        int factorial = 1;
        for (int i = 1; i <= start; i++) {
            factorial *= i;
        }
        sum = sum + factorial;
        start--;
        if (start > 0) {
           sum = factorialSum(start, sum);
        }
        return sum;
    }
}
